using System;
using System.Data;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;

namespace System.Data
{
	[Serializable]
	public abstract class TypedTableBase<T> : System.Data.DataTable, IEnumerable<T>, IEnumerable where T : DataRow
	{
		protected TypedTableBase ()
		{
		}

		protected TypedTableBase (SerializationInfo info, StreamingContext context) : base(info, context)
		{
		}

		public EnumerableRowCollection<TResult> Cast<TResult> ()
		{
			return new EnumerableRowCollection<TResult> (Enumerable.Cast<TResult> (this));
		}

		public IEnumerator<T> GetEnumerator ()
		{
			foreach (object o in Rows)
				yield return (T)o;
		}

		IEnumerator IEnumerable.GetEnumerator ()
		{
			return GetEnumerator ();
		}
	}
}
